package edu.scau.cxq.gp.insert;

import edu.scau.cxq.gp.entity.*;
import edu.scau.cxq.gp.mapper.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * sql插入脚本
 */
@SpringBootTest
public class SQLInsert {

    @Autowired
    private RecordInMapper recordInMapper;

    @Autowired
    private RecordOutMapper recordOutMapper;

    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private WarehouseMapper warehouseMapper;

    @Autowired
    private CustomerMapper customerMapper;

    @Autowired
    private SupplierMapper supplierMapper;

    @Test
    public void insert() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert02() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert03() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert04() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert05() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert06() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert07() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert08() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    @Test
    public void insert09() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    /**
     * 获取随机日期
     * @param beginDate 起始日期，格式为：yyyy-MM-dd
     * @param endDate 结束日期，格式为：yyyy-MM-dd
     * @return
     */
    private static Date randomDate(String beginDate, String endDate){
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date start = format.parse(beginDate);
            Date end = format.parse(endDate);

            if(start.getTime() >= end.getTime()){
                return null;
            }

            long date = random(start.getTime(),end.getTime());

            return new Date(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Test
    public void insert10() {

        List<Goods> goods = goodsMapper.selectList(null);
        List<Customer> customers = customerMapper.selectList(null);
        List<Supplier> suppliers = supplierMapper.selectList(null);
        List<Warehouse> warehouses = warehouseMapper.selectList(null);

        int goodsSize = goods.size();
        int cusSize = customers.size();
        int supSize = suppliers.size();

        for (int i = 0; i < 100000; i++) {
            RecordIn recordIn = new RecordIn();
            RecordOut recordOut = new RecordOut();

            Goods goods1 = goods.get((int) (Math.random() * goodsSize));
            Long goodsId = goods1.getGoodsId();
            Integer goodsCosts = goods1.getGoodsCosts();
            Long cusId = customers.get((int) (Math.random() * cusSize)).getCusId();
            Long supId = suppliers.get((int) (Math.random() * supSize)).getSupId();
            Long wareId = warehouses.get((int) (Math.random() * supSize)).getWareId();

//            System.out.println(goodsId + " " + cusId + " " + supId +  " " + wareId);

            recordIn.setGoodsId(goodsId);
            recordIn.setWareId(wareId);
            recordIn.setSupId(supId);

            recordOut.setGoodsId(goodsId);
            recordOut.setWareId(wareId);
            recordOut.setCusId(cusId);

            int count = (int) (Math.random() * 19) * 10 + 50;
            int amount = (int) Math.ceil((double) count / goodsCosts);

            recordIn.setInCount(count);
            recordIn.setInAmount(amount);

            recordOut.setOutCount(count);

//            System.out.println(count + " " + goodsCosts + " " + amount);
            Date date = randomDate("2015-01-01", "2022-02-22");
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

//            System.out.println(date);
//            System.out.println(localDateTime);

            recordIn.setInTime(localDateTime);

            LocalDateTime localDateTime1 = localDateTime.plusDays((int) (Math.random() * 10));

            recordOut.setOutTime(localDateTime1);

//            System.out.println(localDateTime1);

            int inPrice = (int) (Math.random() * 6) * 500 + 1000;
            int outPrice = inPrice + (int) (Math.random() * 2) * 1000 + 500;

//            System.out.println(inPrice);
//            System.out.println(outPrice);

            recordIn.setInPrice((double) inPrice);
            recordOut.setOutPrice((double) outPrice);
            recordOut.setInPrice((double) inPrice);

//            System.out.println(recordIn);
//            System.out.println(recordOut);

            recordInMapper.insert(recordIn);
            recordOutMapper.insert(recordOut);
        }
    }

    private static long random(long begin,long end){
        long rtn = begin + (long)(Math.random() * (end - begin));
        if(rtn == begin || rtn == end){
            return random(begin,end);
        }
        return rtn;
    }
}
